<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cims</title>

</head>
<body>
    <script src="./jquery.min.js"></script>
    <script>

        var token = null

        // 未授权之前
        $.ajax({
            url: 'http://172.176.1.50:9527/cims/rest/leave/list?pageNum=1&pageSize=10&sortOrder=start_time+desc',
            contentType: 'application/json',
            type: 'GET',
            async: false,
            success(data, status, xhr) {
                console.log(data)
                console.log(status)
            }
        })

        // 授权
        $.ajax({
            url: 'http://172.176.1.50:9527/cims/app/authentication?j_username=admin&j_password=test',
            contentType: 'application/json',
            type: 'POST',
            async: false,
            success(data, status, xhr) {
                // token = data.token
                token = xhr.getResponseHeader('token')
                console.log(data.token)
                console.log(status)
                console.log(xhr.getAllResponseHeaders())
            }
        })

        // document.cookie = token

        // 授权之后
        $.ajax({
            url: 'http://172.176.1.50:9527/cims/rest/leave/list?pageNum=1&pageSize=10&sortOrder=start_time+desc',
            contentType: 'application/json',
            type: 'GET',
            async: false,
            headers: {
                "cookie": token,
                "x-token": token
            },
            xhrFields: {
                withCredentials: true
            },
            success(data, status, xhr) {
                console.log(data)
                console.log(status)
            }
        })

    </script>
</body>
</html>